<!-- HTML header for doxygen 1.8.20-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=9"/>
	<meta name="generator" content="Doxygen 1.9.4"/>
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<title>Raspberry Pi Pico SDK: hardware_base</title>
	<!-- <link href="tabs.css" rel="stylesheet" type="text/css"/> -->
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="dynsections.js"></script>
	<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
	<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
	<link href="doxygen.css" rel="stylesheet" type="text/css" />
	<link href="normalise.css" rel="stylesheet" type="text/css"/>
<link href="main.css" rel="stylesheet" type="text/css"/>
<link href="styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
	<div class="navigation-mobile">
		<div class="logo--mobile">
			<a href="/"><img src="logo-mobile.svg" alt="Raspberry Pi"></a>
		</div>
		<div class="navigation-toggle">
			<span class="line-1"></span>
			<span class="line-2">
				<p>Menu Toggle</p>
			</span>
			<span class="line-3"></span>
		</div>
	</div>
	<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
		<div class="logo">
			<a href="index.html"> <img src="logo.svg" alt="Raspberry Pi"></a>
			<span style="display: inline-block; margin-top: 10px;">
				v2.1.0
			</span>
		</div>
		<div class="navigation-footer">
			<img src="logo-mobile.svg" alt="Raspberry Pi">
			<a href="https://www.raspberrypi.com/" target="_blank">By Raspberry Pi Ltd</a>
		</div>
<!-- 		<div class="search">
			<form>
				<input type="search" name="search" id="search" placeholder="Search">
				<input type="submit" value="Search">
			</form>
		</div> -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('group__hardware__base.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">hardware_base<div class="ingroups"><a class="el" href="group__hardware.html">Hardware APIs</a></div></div></div>
</div><!--header-->
<div class="contents">

<p>Low-level types and (atomic) accessors for memory-mapped hardware registers.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga625e737a57f12211cf1f634ca5095ae4"><td class="memItemLeft" align="right" valign="top">static <a class="el" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__base.html#ga625e737a57f12211cf1f634ca5095ae4">hw_set_bits</a> (io_rw_32 *addr, uint32_t mask)</td></tr>
<tr class="memdesc:ga625e737a57f12211cf1f634ca5095ae4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Atomically set the specified bits to 1 in a HW register.  <a href="group__hardware__base.html#ga625e737a57f12211cf1f634ca5095ae4">More...</a><br /></td></tr>
<tr class="separator:ga625e737a57f12211cf1f634ca5095ae4"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gafd1c089df868d987daf95870b501c2ed"><td class="memItemLeft" align="right" valign="top">static <a class="el" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__base.html#gafd1c089df868d987daf95870b501c2ed">hw_clear_bits</a> (io_rw_32 *addr, uint32_t mask)</td></tr>
<tr class="memdesc:gafd1c089df868d987daf95870b501c2ed"><td class="mdescLeft">&#160;</td><td class="mdescRight">Atomically clear the specified bits to 0 in a HW register.  <a href="group__hardware__base.html#gafd1c089df868d987daf95870b501c2ed">More...</a><br /></td></tr>
<tr class="separator:gafd1c089df868d987daf95870b501c2ed"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga643ecd2ac7ab82d2e1f04dba42135f2b"><td class="memItemLeft" align="right" valign="top">static <a class="el" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__base.html#ga643ecd2ac7ab82d2e1f04dba42135f2b">hw_xor_bits</a> (io_rw_32 *addr, uint32_t mask)</td></tr>
<tr class="memdesc:ga643ecd2ac7ab82d2e1f04dba42135f2b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Atomically flip the specified bits in a HW register.  <a href="group__hardware__base.html#ga643ecd2ac7ab82d2e1f04dba42135f2b">More...</a><br /></td></tr>
<tr class="separator:ga643ecd2ac7ab82d2e1f04dba42135f2b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga81b27e30abef56fe090d22fd8dfdbcc1"><td class="memItemLeft" align="right" valign="top">static <a class="el" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__base.html#ga81b27e30abef56fe090d22fd8dfdbcc1">hw_write_masked</a> (io_rw_32 *addr, uint32_t values, uint32_t write_mask)</td></tr>
<tr class="memdesc:ga81b27e30abef56fe090d22fd8dfdbcc1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Set new values for a sub-set of the bits in a HW register.  <a href="group__hardware__base.html#ga81b27e30abef56fe090d22fd8dfdbcc1">More...</a><br /></td></tr>
<tr class="separator:ga81b27e30abef56fe090d22fd8dfdbcc1"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p >Low-level types and (atomic) accessors for memory-mapped hardware registers. </p>
<p ><code>hardware_base</code> defines the low level types and access functions for memory mapped hardware registers. It is included by default by all other hardware libraries.</p>
<p >The following register access typedefs codify the access type (read/write) and the bus size (8/16/32) of the hardware register. The register type names are formed by concatenating one from each of the 3 parts A, B, C</p>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadNone">A   </th><th class="markdownTableHeadNone">B   </th><th class="markdownTableHeadNone">C   </th><th class="markdownTableHeadNone">Meaning    </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyNone">io_   </td><td class="markdownTableBodyNone"></td><td class="markdownTableBodyNone"></td><td class="markdownTableBodyNone">A Memory mapped IO register    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyNone">&#160;   </td><td class="markdownTableBodyNone">ro_   </td><td class="markdownTableBodyNone"></td><td class="markdownTableBodyNone">read-only access    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyNone">&#160;   </td><td class="markdownTableBodyNone">rw_   </td><td class="markdownTableBodyNone"></td><td class="markdownTableBodyNone">read-write access    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyNone">&#160;   </td><td class="markdownTableBodyNone">wo_   </td><td class="markdownTableBodyNone"></td><td class="markdownTableBodyNone">write-only access (can't actually be enforced via C API)    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyNone">&#160;   </td><td class="markdownTableBodyNone"></td><td class="markdownTableBodyNone">8   </td><td class="markdownTableBodyNone">8-bit wide access    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyNone">&#160;   </td><td class="markdownTableBodyNone"></td><td class="markdownTableBodyNone">16   </td><td class="markdownTableBodyNone">16-bit wide access    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyNone">&#160;   </td><td class="markdownTableBodyNone"></td><td class="markdownTableBodyNone">32   </td><td class="markdownTableBodyNone">32-bit wide access   </td></tr>
</table>
<p >When dealing with these types, you will always use a pointer, i.e. <code>io_rw_32 *some_reg</code> is a pointer to a read/write 32 bit register that you can write with <code>*some_reg = value</code>, or read with <code>value = *some_reg</code>.</p>
<p >RP-series hardware is also aliased to provide atomic setting, clear or flipping of a subset of the bits within a hardware register so that concurrent access by two cores is always consistent with one atomic operation being performed first, followed by the second.</p>
<p >See <a class="el" href="group__hardware__base.html#ga625e737a57f12211cf1f634ca5095ae4" title="Atomically set the specified bits to 1 in a HW register.">hw_set_bits()</a>, <a class="el" href="group__hardware__base.html#gafd1c089df868d987daf95870b501c2ed" title="Atomically clear the specified bits to 0 in a HW register.">hw_clear_bits()</a> and <a class="el" href="group__hardware__base.html#ga643ecd2ac7ab82d2e1f04dba42135f2b" title="Atomically flip the specified bits in a HW register.">hw_xor_bits()</a> provide for atomic access via a pointer to a 32 bit register</p>
<p >Additionally given a pointer to a structure representing a piece of hardware (e.g. <code><a class="el" href="structdma__hw__t.html">dma_hw_t</a> *dma_hw</code> for the DMA controller), you can get an alias to the entire structure such that writing any member (register) within the structure is equivalent to an atomic operation via hw_set_alias(), hw_clear_alias() or hw_xor_alias()...</p>
<p >For example <code>hw_set_alias(dma_hw)-&gt;inte1 = 0x80;</code> will set bit 7 of the INTE1 register of the DMA controller, leaving the other bits unchanged. </p>
<h2 class="groupheader">Function Documentation</h2>
<a id="gafd1c089df868d987daf95870b501c2ed" name="gafd1c089df868d987daf95870b501c2ed"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gafd1c089df868d987daf95870b501c2ed">&#9670;&nbsp;</a></span>hw_clear_bits()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static <a class="el" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> void hw_clear_bits </td>
          <td>(</td>
          <td class="paramtype">io_rw_32 *&#160;</td>
          <td class="paramname"><em>addr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>mask</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Atomically clear the specified bits to 0 in a HW register. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">addr</td><td>Address of writable register </td></tr>
    <tr><td class="paramname">mask</td><td>Bit-mask specifying bits to clear </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ga625e737a57f12211cf1f634ca5095ae4" name="ga625e737a57f12211cf1f634ca5095ae4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga625e737a57f12211cf1f634ca5095ae4">&#9670;&nbsp;</a></span>hw_set_bits()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static <a class="el" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> void hw_set_bits </td>
          <td>(</td>
          <td class="paramtype">io_rw_32 *&#160;</td>
          <td class="paramname"><em>addr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>mask</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Atomically set the specified bits to 1 in a HW register. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">addr</td><td>Address of writable register </td></tr>
    <tr><td class="paramname">mask</td><td>Bit-mask specifying bits to set </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ga81b27e30abef56fe090d22fd8dfdbcc1" name="ga81b27e30abef56fe090d22fd8dfdbcc1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga81b27e30abef56fe090d22fd8dfdbcc1">&#9670;&nbsp;</a></span>hw_write_masked()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static <a class="el" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> void hw_write_masked </td>
          <td>(</td>
          <td class="paramtype">io_rw_32 *&#160;</td>
          <td class="paramname"><em>addr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>values</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>write_mask</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Set new values for a sub-set of the bits in a HW register. </p>
<p >Sets destination bits to values specified in <code>values</code>, if and only if corresponding bit in <code>write_mask</code> is set</p>
<p >Note: this method allows safe concurrent modification of <em>different</em> bits of a register, but multiple concurrent access to the same bits is still unsafe.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">addr</td><td>Address of writable register </td></tr>
    <tr><td class="paramname">values</td><td>Bits values </td></tr>
    <tr><td class="paramname">write_mask</td><td>Mask of bits to change </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ga643ecd2ac7ab82d2e1f04dba42135f2b" name="ga643ecd2ac7ab82d2e1f04dba42135f2b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga643ecd2ac7ab82d2e1f04dba42135f2b">&#9670;&nbsp;</a></span>hw_xor_bits()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static <a class="el" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> void hw_xor_bits </td>
          <td>(</td>
          <td class="paramtype">io_rw_32 *&#160;</td>
          <td class="paramname"><em>addr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>mask</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Atomically flip the specified bits in a HW register. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">addr</td><td>Address of writable register </td></tr>
    <tr><td class="paramname">mask</td><td>Bit-mask specifying bits to invert </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->

	<script src="main.js"></script>
</body>
</html>